package me.zk.practice1.hw;

import java.util.*;

/**
 * @author zhangkai
 * @date 2023/8/8 12:22
 */
public class HWBJ41 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        Map<String,Integer> map = new TreeMap<>();

        while (scanner.hasNext()) {
            String str = scanner.nextLine();
            if (!str.contains(".")){
                int n = Integer.parseInt(str);

                if (n > map.size()){
                    break;
                }

                List<Map.Entry<String,Integer>> list = new ArrayList<>(map.entrySet());

                list.sort(Comparator.comparingInt(Map.Entry::getValue));
                StringBuilder res = new StringBuilder();
                for (int i = 0; i < n; i++) {
                  res.append(list.get(1).getKey());
                  if (i != n-1) {
                      res.append(",");
                  }
                }
                System.out.println(res);



            } else {
                map.put(str,map.getOrDefault(str,0)+1);
            }

        }
    }
}
